/*
 * CreateServerButtonListener.cpp
 *
 *  Created on: Oct 24, 2011
 *      Author: gonzalo
 */

#include "CreateServerButtonListener.h"

CreateServerButtonListener::CreateServerButtonListener(Textbox* port,ItemList* scenarioList) {
	this->port = port;
	this->scenarioList = scenarioList;
}

void CreateServerButtonListener::execute() {
	std::string hostPort = this->port->getInput();
	std::string scenario = this->scenarioList->getSelected();

	if (hostPort.length()!=0 && scenario.length()!=0){
		pushEventCreateServer(hostPort,scenario);
	}
}

void CreateServerButtonListener::pushEventCreateServer(std::string port, std::string scenarioName) {

	//Junto el ip y puerto y creo el evento
	SDL_Event event1;
	event1.type = SDL_USEREVENT;
	event1.user.code = CREATE;
	event1.user.data1 = new std::string(port);
	event1.user.data2 = new std::string(scenarioName);
	SDL_PushEvent(&event1);
}
